import Nerv from "nervjs";
import Taro from "@tarojs/taro-h5";
import { View } from '@tarojs/components';
import { AtTabBar } from 'taro-ui';
import MyList from '../components/my/list';
import MyHistory from '../components/my/history';
import New from '../components/my/new';
import Global from '../utils/global';
import './index.scss';
export default class IndexPage extends Taro.Component {
  constructor() {
    super(...arguments);

    this.state = {
      tabIndex: 0
    };
  }
  //////////////////////////////////// Hooks ////////////////////////////////
  componentWillMount() {
    if (!Global.get('token')) {
      Taro.redirectTo({
        url: './login/login'
      });
    }
  }
  //////////////////////////////////// Render ////////////////////////////////
  render() {
    const { tabIndex } = this.state;
    const tabList = [{ title: '跟踪', iconType: 'bell' }, { title: '申请', iconType: 'add-circle' }, { title: '历史', iconType: 'list' }];
    return <View>
        {tabIndex == 0 && <MyList />}
        {tabIndex == 1 && <New />}
        {tabIndex == 2 && <MyHistory />}
        <AtTabBar fixed tabList={tabList} onClick={this.tabClick.bind(this)} current={tabIndex} />
      </View>;
  }
  //////////////////////////////////// Events ///////////////////////////////
  tabClick(value) {
    this.setState({
      tabIndex: value
    });
  }
  config = {
    navigationBarTitleText: '报修系统'
  };

  componentDidMount() {
    super.componentDidMount && super.componentDidMount();
  }

  componentDidShow() {
    super.componentDidShow && super.componentDidShow();
  }

  componentDidHide() {
    super.componentDidHide && super.componentDidHide();
  }

}